
#include"../http/httplib.h"
#include"searcher.hpp"

const std::string input = "data/raw_html/raw.txt";
const std::string root_path = "./wwwroot";
int main()
{
    ns_sercher::Searcher search;
    search.InitSearchar(input);
    httplib::Server svr;
    svr.set_base_dir(root_path.c_str());
    svr.Get("/s",[&search](const httplib::Request &req,httplib::Response &rsp){
        if(!req.has_param("word"))
        {
            rsp.set_content("关键字","text/plain;charset=utf-8");
            return;
        }
        std::string word = req.get_param_value("word");
        //日志
        std::string json_string;
         search.Search(word,&json_string);
         rsp.set_content(json_string,"application/json");
    });
    //日志
    svr.listen("0.0.0.0",8081);
    return 0;
}